﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IsmsExplorer.Infrastructure.DomainBase;
using IsmsExplorer.Model.Projects;
using IsmsExplorer.Model.RiskRegister;
using System.Diagnostics;

namespace IsmsExplorer.Model.AssetRegister {
    public class Asset : IdNameEntity {
        private int _valueCIA;
        private Project _project;
        private AssetCategory _category;
        private Role _owner;
        private Location _location;
        private List<Threat> _threats = new List<Threat>();        

        public Asset(int id, string name, int valueCIA) : base(id, name) 
        {
            this._valueCIA = valueCIA;
        }
        public Asset() : this(0, string.Empty, 0) 
        {
        }

        public int ValueCIA {
            get { return _valueCIA; }
            set { _valueCIA = value; }
        }

        public Project Project {
            get { return _project; }
            set { _project = value; }
        }

        public AssetCategory Category {
            get { return _category; }
            set { _category = value; }
        }

        public Role Owner {
            get { return _owner; }
            set { _owner = value; }
        }

        public Location Location {
            get { return _location; }
            set { _location = value; }
        }

        public IEnumerable<Threat> Threats {
            get { return _threats.AsReadOnly(); }
            //set { _threats = value; }
        }

        public void AddThreat(Threat threat) {
#if DEBUG
            foreach (var t in _threats) {
                if (t == threat) {
                    throw new InvalidOperationException("threat already added");
                }
            }
#endif
            threat.Asset = this;
            _threats.Add(threat);
        }

        public void RemoveThreat(Threat threat) {
            //foreach (var d in _threats) {
            //    if (d == doc) {                    
            //        _threats.Remove(d);
            //        break;
            //    }
            //}
            _threats.Remove(threat);
        }

    } // end public class Asset : IdNameEntity
}
